package com.aisile.user.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @Auther:yry
 * @Date:2024/1/3 0003
 * @VERSON:1.0
 */
@Configuration
public class FeignTokenConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        String token =  requestAttributes.getRequest().getHeader("token");
        // 请求之前 携带token就行了
        requestTemplate.header("token",token);
    }
}
